﻿namespace DynamicPatterns.Tests
{
	using Microsoft.CSharp.RuntimeBinder;
	using Microsoft.VisualStudio.TestTools.UnitTesting;
	using System;
	using System.Collections.Dynamic;

	[TestClass]
	public class CollectionTests
	{
		[TestMethod]
		public void DynamicDictionary()
		{
			dynamic d = new DynamicDictionary();
			Assert.AreEqual(d.Count, 0);

			d.A = 'B';
			d.B = 2;
			Assert.AreEqual(d.Count, 2);
			Assert.AreEqual('B', d.A);
			Assert.AreEqual(2, d.B);

			d.A = "expected";
			Assert.AreEqual(d.Count, 2);
			Assert.AreEqual("expected", d.A);
		}

		[TestMethod]
		[ExpectedException(typeof(RuntimeBinderException))]
		public void DynamicDictionary_KeyNotFound()
		{
			dynamic d = new DynamicDictionary();
			Assert.IsNotNull(d.A);
		}

		[TestMethod]
		[ExpectedException(typeof(ArgumentNullException))]
		public void DynamicDictionary_ArgumentNull()
		{
			dynamic d = new DynamicDictionary(null);
		}
	}
}
